package com.woniuxy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.entity.Model;
import com.woniuxy.entity.Specs;
import com.woniuxy.provider.SpecsProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface SpecsMapper extends BaseMapper<Specs> {
    /**
     *新增规格
     * @param specs
     */
    @Insert("insert into gfr_specs(name,value,sort,status) " +
            "values(#{name},#{value},#{sort},#{status})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void add(Specs specs);

    @UpdateProvider(type = SpecsProvider.class,method = "update")
    void update(Specs specs);

    /**
     * 根据id删除规格,逻辑删除
     * @author wmy
     */
    @Update("update gfr_specs set status='n' where id=#{id}")
    void deleteById(int id);

    @SelectProvider(type = SpecsProvider.class, method = "getByCondition")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "value",property = "value"),
            @Result(column = "sort",property = "sort"),
            @Result(column = "status",property = "status"),
    })
    List<Specs> getByCondition(Specs specs);

    @Select("select * from gfr_specs where name=#{name}")
    Specs getByName(String name);


    @Select("select * from gfr_specs")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name", property = "name"),
    })
    List<Specs> getAll();
    @Select("select * from gfr_specs where id=#{parseInt}")
    Specs getById(int parseInt);
}
